package com.situ.achievementsystem.department.service;

import java.util.List;

import com.situ.achievementsystem.department.dao.DepartmentDao;
import com.situ.achievementsystem.department.model.DepartmentModel;

public class DepartmentService {

private DepartmentDao dao = new DepartmentDao();
	
	public String insert(DepartmentModel model) {
		return selectModel(model) == null?dao.insert(model):"rgp";
	}
	
	public String delete(DepartmentModel model) {
		return dao.delete(model);
	}
	
	public String update(DepartmentModel model) {
		return dao.update(model);
	}
	
	public List<DepartmentModel> selectList(DepartmentModel model) {
		String code = model.getCode();
		code = code ==null || code.trim().isEmpty()?"":code;
		model.setCode("%" + code + "%");//"%" + code + "%"
		String name = model.getName();
		name = name ==null || name.trim().isEmpty()?"":name;
		model.setName("%" + name + "%");
//		String del = model.getDel();
//		del = code ==null || del.trim().isEmpty()?"":del;
//		model.setDel("%" + del + "%");
//		System.out.println(dao.select(model));
		return dao.select(model);
	}
	
	public DepartmentModel selectModel(DepartmentModel model) {
		DepartmentModel temp = new DepartmentModel();
		temp.setCode(model.getCode());
		List<DepartmentModel> list = dao.select(model);
		if(list==null || list.isEmpty())
			return null;
		return list.get(0);
	}

//	public String login(DepartmentModel model) {
//		DepartmentModel m1 = new DepartmentModel(model.getCode());
//		List<DepartmentModel> list = dao.select(m1);
//		if(list==null||list.isEmpty()) {
//			return "0";
//		}
//		DepartmentModel m2 = list.get(0);
//		if(m2.getName().equals(model.getName())) {
//			return "1";
//		}else {
//			return "2";
//		}
//	}
}
